/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.asportoonline.controller;

import java.util.HashMap;
import java.util.Map;

import org.asportoonline.configuration.Configuration;
import org.asportoonline.context.RequestObject;
/**
 *
 * @author Valerio Costmagna <costamagna.valerio@gmail.com>
 */
public class ActionFactory {


	protected static Map actions = new HashMap();

	public static Action createAction(RequestObject requestObject) throws Exception {

		Action action = (Action) actions.get(requestObject.getRequestCommmand());

		if (action == null)
		{
			String actionClassName = Configuration.getAction(requestObject.getRequestCommmand());
			if (actionClassName == null)
				throw new Exception();
			try
			{
				action = (Action) Class.forName(actionClassName).newInstance();
				actions.put(requestObject.getRequestCommmand(), action);
			}
			catch (Throwable t)
			{
				throw new Exception();
			}
		}

		return action;
	}
}
